
#ifndef XDNS_QUERY_H
#define XDNS_QUERY_H

#include "xdns.h"

enum XdnsQueryType
{
    XQT_Hostname,
    XQT_IpAddress
};

class XdnsData;
class XdnsQuestionInfo;

class XdnsQuery
{
public:
    XdnsQuery(XdnsQueryType type,
              XdnsListener* listener);
    virtual ~XdnsQuery();

    /*! Compose a DNS query of data.

        This function composes a DNS query of data with a single question,
        the data is used to be sent through network to request a DNS
        answer.

        @param requestId A 16 bit identifier assigned in the DNS header
                         section, this identifier is copied the corresponding
                         reply and can be used by the requester to match up
                         replies to outstanding queries.
        @param data On return the data of this DNS query to send.
        @return XE_Ok if success.
    */
    virtual XdnsError ComposeQueryData(unsigned short requestId,
                                       XdnsData& data
                                       ) const = 0;

    /*! Retrieve the info of DNS question section for this query.

        @param question On return the question info for this query.
        @return None.
    */
    virtual void GetQuestion(XdnsQuestionInfo& question) const = 0;

    /*! Retrieve the start offset of data for TCP to send.

        @return Start offset of data for TCP.
    */
    virtual size_t GetTcpStartOffset() const;

    /*! Retrieve the start offset of data for UDP to send.

        @return Start offset of data for UDP.
    */
    virtual size_t GetUdpStartOffset() const;

    XdnsQueryType GetType() const;
    void NotifyListener(long queryId,
                        XdnsError error,
                        const std::vector<XdnsHostEntry*>* hostEntries);

private:
    // Copy constructor and assignment operator are not supported.
    XdnsQuery(const XdnsQuery& anotherQuery);
    XdnsQuery& operator=(const XdnsQuery& anotherQuery);

    XdnsQueryType m_type;
    XdnsListener* m_listener;
};

#endif  // XDNS_QUERY_H

